/* Try using the .writeMicroseconds(uS); between 1000 and 2000.  Look for min
    and max value.
   Right now, write 35 at beginning to all motors, power up, and wait for beeps.
     Then write at least 52? to start the motors.
   To program ESC's, write 135?(full throttle), follow instructions on datasheet

   Currently there may be issues with syncing of PPM signals   
    
*/

#include <Servo.h> 
 
Servo motors[4];  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
int pins[4] = {5,6,11,9};
 
int pos[4] = {0, 0, 0, 0};    // variable to store the servo position 
int count = 0;

void setup() 
{ 
  for(int i = 0; i<4; i++)
  {
     motors[i].attach(pins[i]); 
  }
  Serial.begin(9600);
} 
 
 
void loop() 
{ 
    if(Serial.available()>0)
    {
        pos[count] = Serial.parseInt();
        Serial.print("Motor #");
        Serial.print(count+1);
        Serial.print(" at ");
        Serial.print(pins[count]);
        Serial.print(": ");
        Serial.println(pos[count]);
        count++;
        if(count>3)
          count = 0;
    }
    for(int i = 0; i<4; i++)
    {
       motors[i].write(pos[i]); 
    }
    delay(20);
  
} 
